package coordinator; 

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.rmi.RemoteException;

import testnode.ITestNode;

import com.healthmarketscience.rmiio.GZIPRemoteInputStream;
import com.healthmarketscience.rmiio.RemoteInputStreamServer;

public class Coordinator implements ICoordinator {

	/**
	 * @param args
	 */
	public void InstallOnTestNode(ITestNode testNode, File f) throws Exception {
		RemoteInputStreamServer istream = null;
		try {
			istream = new GZIPRemoteInputStream(new BufferedInputStream(
					new FileInputStream(f)));
			// call server (note export() call to get actual remote interface)
			testNode.installFile(f.getName(), istream.export());
		} finally {
			// since the server should have consumed the stream in the
			// sendFile()
			// call, we always want to close the stream
			if (istream != null)
				istream.close();
		}
	}
	
	public void executeOnTestNode(ITestNode testNode, String className, String[] args) {
		try {
			testNode.execute(className, "main", args);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
